// Decompiled by DJ v3.10.10.93 Copyright 2007 Atanas Neshkov  Date: 20/11/2009 15:49:15
// Home Page: http://members.fortunecity.com/neshkov/dj.html  http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   Connector.java

package leica.wrapper;

import java.io.PrintStream;
import org.w3c.dom.Element;

// Referenced classes of package leica.wrapper:
//            SessionManager, ConnectorInterface, LeicaToApplication, LeicaInterface

public class Connector
    implements ConnectorInterface
{

    public Connector(LeicaToApplication leicatoapplication)
    {
        try
        {
            toLeica = new SessionManager(this);
        }
        catch(Exception exception)
        {
            System.err.println("LEICA Msg: error creating SessionManager");
        }
        toCA = leicatoapplication;
    }

    String[][] reOrder(String as[], String as1[][])
    {
        String as2[][] = new String[as.length][];
label0:
        for(int i = 0; i < as.length; i++)
        {
            int j = 0;
            do
            {
                if(j >= as.length)
                    continue label0;
                if(as1[j][0].equals(as[i]))
                {
                    as2[i] = as1[j];
                    continue label0;
                }
                j++;
            } while(true);
        }

        return as2;
    }

    public void treatActionReq(String s, String as[][])
    {
        if(s.equals("createConference"))
        {
            System.out.println("Connector.treatActionReq()----> if(s.equals(changeConference)");
            String as1[] = {
                "spSid", "usersList"
            };
            as = reOrder(as1, as);
            String s1 = as[0][1];
            String as8[] = new String[as[1].length - 1];
            System.arraycopy(as[1], 1, as8, 0, as[1].length - 1);
            toCA.do_createConference(s1, as8);
        } else
        if(s.equals("createSpecificConference"))
        {
            String as2[] = {
                "spSid", "usersList", "conf"
            };
            as = reOrder(as2, as);
            String s2 = as[0][1];
            String as9[] = new String[as[1].length - 1];
            System.arraycopy(as[1], 1, as9, 0, as[1].length - 1);
            int i = Integer.parseInt(as[2][1]);
            toCA.do_createSpecificConference(s2, as9, i);
        } else
        if(s.equals("changeConference"))
        {
            String as3[] = {
                "spSid", "user", "confSource", "confDest"
            };
            as = reOrder(as3, as);
            String s3 = as[0][1];
            String s8 = as[1][1];
            int j = Integer.parseInt(as[2][1]);
            int k = Integer.parseInt(as[3][1]);
            toCA.do_changeConference(s3, s8, j, k);
        } else
        if(s.equals("addUsersToConference"))
        {
            System.out.println("Connector.treatActionReq()----> if(s.equals(addUsersToConference)");
            String as4[] = {
                "spSid", "userDest", "usersSrc"
            };
            as = reOrder(as4, as);
            String s4 = as[0][1];
            String s9 = as[1][1];
            String as10[] = new String[as[2].length - 1];
            System.arraycopy(as[2], 1, as10, 0, as[2].length - 1);
            toCA.do_addUsersToConference(s4, s9, as10);
        } else
        if(s.equals("delUserConference"))
        {
            String as5[] = {
                "spSid", "user"
            };
            as = reOrder(as5, as);
            String s5 = as[0][1];
            String s10 = as[1][1];
            toCA.do_delUserConference(s5, s10);
        } else
        if(s.equals("CONNECT"))
        {
            String as6[] = {
                "spSid", "user"
            };
            as = reOrder(as6, as);
            String s6 = as[0][1];
            String s11 = as[1][1];
            toCA.do_CONNECT(s6, s11);
        } else
        if(s.equals("DISCONNECT"))
        {
            String as7[] = {
                "spSid", "user"
            };
            as = reOrder(as7, as);
            String s7 = as[0][1];
            String s12 = as[1][1];
            toCA.do_DISCONNECT(s7, s12);
        }
    }

    public void treatActionReq(Element element)
    {
        toCA.createspS(element);
    }

    public void treatActionReq(String s)
    {
        toCA.terminatespS(s);
    }

    public void notify_userJoinedConference(String s, int i, String s1, String s2)
    {
        String as[][] = new String[4][];
        String as1[] = {
            "spSid", s
        };
        as[0] = as1;
        String as2[] = {
            "Integer.toString(conferenceNum)", Integer.toString(i)
        };
        as[1] = as2;
        String as3[] = {
            "userID", s1
        };
        as[2] = as3;
        String as4[] = {
            "user", s2
        };
        as[3] = as4;
        if(toLeica != null)
            toLeica.notifyEvent("userJoinedConference", as);
    }

    public void notify_userLeaveConference(String s, int i, String s1, String s2)
    {
        String as[][] = new String[4][];
        String as1[] = {
            "spSid", s
        };
        as[0] = as1;
        String as2[] = {
            "Integer.toString(conferenceNum)", Integer.toString(i)
        };
        as[1] = as2;
        String as3[] = {
            "userID", s1
        };
        as[2] = as3;
        String as4[] = {
            "user", s2
        };
        as[3] = as4;
        if(toLeica != null)
            toLeica.notifyEvent("userLeaveConference", as);
    }

    public void notify_CONNECT(String s, String s1, String s2)
    {
        String as[][] = {
            {
                "spSid", s
            }, {
                "Uid", s1
            }, {
                "sRlid", s2
            }
        };
        toLeica.notifyEvent("CONNECT", as);
    }

    public void notify_DISCONNECT(String s, String s1)
    {
        String as[][] = {
            {
                "spSid", s
            }, {
                "Uid", s1
            }
        };
        toLeica.notifyEvent("DISCONNECT", as);
    }

    LeicaToApplication toCA;
    LeicaInterface toLeica;
}